home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '88 / Other stuff / benchmark / dhrystone.c
Encoding:
C/C++ Source or Header  |  1987-12-17  |  11.1 KB  |  406 lines  |  [TEXT/KAHL]

  1. /*
  2.  *      "DHRYSTONE" Benchmark Program
  3.  *
  4.  *      Compile:        cl dry.c  (Microsoft 3.0)
  5.  *      Defines:        Defines are provided for old C compiler's
  6.  *                      which don't have enums, and can't assign structures.
  7.  *                      The time(2) function is library dependant; One is
  8.  *                      provided for CI-C86.  Your compiler may be different.
  9.  *                      This is not required for Microsoft 3.0 which supports
  10.  *                      all of the standard calls and will compile asis.
  11.  *
  12.  *      MACHINE                 OPERATING       COMPILER         DHRYSTONES 
  13.  *      TYPE                    SYSTEM                            /SEC      
  14.  *      ---------------         ------------    ---------------  -----------
  15.  *      IBM PC/XT               PCDOS 3.1       Microsoft C 3.0      333
  16.  *      IBM PC/AT               PCDOS 3.1       Microsoft C 3.0     1041
  17.  *    $ IBM PC/AT               PCDOS 3.0       CI-C86 2.1           684
  18.  *    $ ATT 3B2/300             UNIX 5.2        cc                   806
  19.  *    $ IBM PC/AT               VENIX/86 2.1    cc                  1000
  20.  *    $ Sun2/120                Sun 4.2BSD      cc                  1219
  21.  *    + Sun 3/50 (ebony)    Sun 3.4        cc            2183
  22.  *    + Sun 3/50 (fuchsia) FP     "        cc            2380
  23.  *      Sun 3/50 (orange)        "        "            2380
  24.  *    Sun 3/60 (jade)         "        "            3846
  25.  *    + Sun 3/160 (green)    Sun 3.4        cc            3125
  26.  *
  27.  *    The entries with $ supplied by Rick Richardson, who origanally converted
  28.  *    the program from ADA.
  29.  *    The rest are provided by Mike's "C" Board 619-722-8724 
  30.  *    The entries with + was an average of 10 runs at 9am, light load.
  31.  **************************************************************************
  32.  *
  33.  *      The following program contains statements of a high-level programming
  34.  *      language (C) in a distribution considered representative:
  35.  *
  36.  *      assignments                     53%
  37.  *      control statements              32%
  38.  *      procedure, function calls       15%
  39.  *
  40.  *      100 statements are dynamically executed.  The program is balanced with
  41.  *      respect to the three aspects:
  42.  *              - statement type
  43.  *              - operand type (for simple data types)
  44.  *              - operand access
  45.  *                      operand global, local, parameter, or constant.
  46.  *
  47.  *      The combination of these three aspects is balanced only approximately.
  48.  *
  49.  *      The program does not compute anything meaningfull, but it is
  50.  *      syntactically and semantically correct.
  51.  *
  52.  */
  53.  
  54. /* Compiler dependent options */
  55. #undef  NOENUM                  /* Define if compiler has no enum's */
  56. #define  NOSTRUCTASSIGN          /* Define if compiler can't assign structures */
  57. #undef  NOTIME                  /* Define if no time() function in library */
  58. #define  MACINTOSH               /* Define if a macintosh */
  59.  
  60. #ifdef  MACINTOSH
  61. #define malloc(A)    NewPtr(A)
  62. #endif
  63.  
  64. #ifdef  NOSTRUCTASSIGN
  65. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  66. #else
  67. #define structassign(d, s)      d = s
  68. #endif
  69.  
  70. #ifdef  NOENUM
  71. #define Ident1  1
  72. #define Ident2  2
  73. #define Ident3  3
  74. #define Ident4  4
  75. #define Ident5  5
  76. typedef int     Enumeration;
  77. #else
  78. typedef enum    {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  79. #endif
  80.  
  81. typedef int     OneToThirty;
  82. typedef int     OneToFifty;
  83. typedef char    CapitalLetter;
  84. typedef char    String30[31];
  85. typedef int     Array1Dim[51];
  86. typedef int     Array2Dim[51][51];
  87.  
  88. struct  Record
  89. {
  90.         struct Record           *PtrComp;
  91.         Enumeration             Discr;
  92.         Enumeration             EnumComp;
  93.         OneToFifty              IntComp;
  94.         String30                StringComp;
  95. };
  96.  
  97. typedef struct Record   RecordType;
  98. typedef RecordType *    RecordPtr;
  99. typedef int             boolean;
  100.  
  101. #define NULL            0
  102. #define TRUE            1
  103. #define FALSE           0
  104.  
  105. #ifndef REG
  106. #define REG
  107. #endif
  108.  
  109. extern Enumeration      Func1();
  110. extern boolean          Func2();
  111.  
  112. main()
  113. {
  114.         Proc0();
  115. }
  116.  
  117. /*
  118.  * Package 1
  119.  */
  120. int             IntGlob;
  121. boolean         BoolGlob;
  122. char            Char1Glob;
  123. char            Char2Glob;
  124. Array1Dim       Array1Glob;
  125. Array2Dim       Array2Glob;
  126. RecordPtr       PtrGlob;
  127. RecordPtr       PtrGlobNext;
  128.  
  129. Proc0()
  130. {
  131.         OneToFifty              IntLoc1;
  132.         REG OneToFifty          IntLoc2;
  133.         OneToFifty              IntLoc3;
  134.         REG char                CharLoc;
  135.         REG char                CharIndex;
  136.         REG Enumeration         EnumLoc;
  137.         String30                String1Loc;
  138.         String30                String2Loc;
  139.  
  140. #define LOOPS           50000
  141. unsigned long                    time();
  142. unsigned long                    starttime;
  143. unsigned long                    benchtime;
  144. unsigned long                    nulltime;
  145. register unsigned int   i;
  146.  
  147. char    dumi[10];
  148.  
  149.  
  150. starttime = time(0);
  151. for (i = 0; i < LOOPS; ++i);
  152. nulltime = time(0) - starttime;
  153.  
  154.         PtrGlobNext = (RecordPtr) malloc(sizeof(RecordType));
  155.         PtrGlob = (RecordPtr) malloc(sizeof(RecordType));
  156.         PtrGlob->PtrComp = PtrGlobNext;
  157.         PtrGlob->Discr = Ident1;
  158.         PtrGlob->EnumComp = Ident3;
  159.         PtrGlob->IntComp = 40;
  160.         strcpy(PtrGlob->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  161.  
  162. /*****************
  163. -- Start Timer --
  164. *****************/
  165. starttime = time(0);
  166. for (i = 0; i < LOOPS; ++i)
  167. {
  168.  
  169.         Proc5();
  170.         Proc4();
  171.         IntLoc1 = 2;
  172.         IntLoc2 = 3;
  173.         strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  174.         EnumLoc = Ident2;
  175.         BoolGlob = ! Func2(String1Loc, String2Loc);
  176.         while (IntLoc1 < IntLoc2)
  177.         {
  178.                 IntLoc3 = 5 * IntLoc1 - IntLoc2;
  179.                 Proc7(IntLoc1, IntLoc2, &IntLoc3);
  180.                 ++IntLoc1;
  181.         }
  182.         Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  183.         Proc1(PtrGlob);
  184.         for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  185.                 if (EnumLoc == Func1(CharIndex, 'C'))
  186.                         Proc6(Ident1, &EnumLoc);
  187.         IntLoc3 = IntLoc2 * IntLoc1;
  188.         IntLoc2 = IntLoc3 / IntLoc1;
  189.         IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  190.         Proc2(&IntLoc1);
  191.  
  192. /*****************
  193. -- Stop Timer --
  194. *****************/
  195. }
  196. benchtime = time(0) - starttime - nulltime;
  197. printf("Dhrystone time for %ld passes = %ld\n", (long) LOOPS, benchtime);
  198. printf("This machine benchmarks at %ld dhrystones/second\n",
  199.         ((long) LOOPS) / benchtime);
  200.  
  201. }
  202.  
  203. Proc1(PtrParIn)
  204. REG RecordPtr   PtrParIn;
  205. {
  206. #define NextRecord      (*(PtrParIn->PtrComp))
  207.  
  208.         structassign(NextRecord, *PtrGlob);
  209.         PtrParIn->IntComp = 5;
  210.         NextRecord.IntComp = PtrParIn->IntComp;
  211.         NextRecord.PtrComp = PtrParIn->PtrComp;
  212.         Proc3(NextRecord.PtrComp);
  213.         if (NextRecord.Discr == Ident1)
  214.         {
  215.                 NextRecord.IntComp = 6;
  216.                 Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  217.                 NextRecord.PtrComp = PtrGlob->PtrComp;
  218.                 Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
  219.         }
  220.         else
  221.                 structassign(*PtrParIn, NextRecord);
  222.  
  223. #undef  NextRecord
  224. }
  225.  
  226. Proc2(IntParIO)
  227. OneToFifty      *IntParIO;
  228. {
  229.         REG OneToFifty          IntLoc;
  230.         REG Enumeration         EnumLoc;
  231.  
  232.         IntLoc = *IntParIO + 10;
  233.         for(;;)
  234.         {
  235.                 if (Char1Glob == 'A')
  236.                 {
  237.                         --IntLoc;
  238.                         *IntParIO = IntLoc - IntGlob;
  239.                         EnumLoc = Ident1;
  240.                 }
  241.                 if (EnumLoc == Ident1)
  242.                         break;
  243.         }
  244. }
  245.  
  246. Proc3(PtrParOut)
  247. RecordPtr       *PtrParOut;
  248. {
  249.         if (PtrGlob != NULL)
  250.                 *PtrParOut = PtrGlob->PtrComp;
  251.         else
  252.                 IntGlob = 100;
  253.         Proc7(10, IntGlob, &PtrGlob->IntComp);
  254. }
  255.  
  256. Proc4()
  257. {
  258.         REG boolean     BoolLoc;
  259.  
  260.         BoolLoc = Char1Glob == 'A';
  261.         BoolLoc |= BoolGlob;
  262.         Char2Glob = 'B';
  263. }
  264.  
  265. Proc5()
  266. {
  267.         Char1Glob = 'A';
  268.         BoolGlob = FALSE;
  269. }
  270.  
  271. extern boolean Func3();
  272.  
  273. Proc6(EnumParIn, EnumParOut)
  274. REG Enumeration EnumParIn;
  275. REG Enumeration *EnumParOut;
  276. {
  277.         *EnumParOut = EnumParIn;
  278.         if (! Func3(EnumParIn) )
  279.                 *EnumParOut = Ident4;
  280.         switch (EnumParIn)
  281.         {
  282.         case Ident1:    *EnumParOut = Ident1; break;
  283.         case Ident2:    if (IntGlob > 100) *EnumParOut = Ident1;
  284.                         else *EnumParOut = Ident4;
  285.                         break;
  286.         case Ident3:    *EnumParOut = Ident2; break;
  287.         case Ident4:    break;
  288.         case Ident5:    *EnumParOut = Ident3;
  289.         }
  290. }
  291.  
  292. Proc7(IntParI1, IntParI2, IntParOut)
  293. OneToFifty      IntParI1;
  294. OneToFifty      IntParI2;
  295. OneToFifty      *IntParOut;
  296. {
  297.         REG OneToFifty  IntLoc;
  298.  
  299.         IntLoc = IntParI1 + 2;
  300.         *IntParOut = IntParI2 + IntLoc;
  301. }
  302.  
  303. Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
  304. Array1Dim       Array1Par;
  305. Array2Dim       Array2Par;
  306. OneToFifty      IntParI1;
  307. OneToFifty      IntParI2;
  308. {
  309.         REG OneToFifty  IntLoc;
  310.         REG OneToFifty  IntIndex;
  311.  
  312.         IntLoc = IntParI1 + 5;
  313.         Array1Par[IntLoc] = IntParI2;
  314.         Array1Par[IntLoc+1] = Array1Par[IntLoc];
  315.         Array1Par[IntLoc+30] = IntLoc;
  316.         for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  317.                 Array2Par[IntLoc][IntIndex] = IntLoc;
  318.         ++Array2Par[IntLoc][IntLoc-1];
  319.         Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  320.         IntGlob = 5;
  321. }
  322.  
  323. Enumeration Func1(CharPar1, CharPar2)
  324. CapitalLetter   CharPar1;
  325. CapitalLetter   CharPar2;
  326. {
  327.         REG CapitalLetter       CharLoc1;
  328.         REG CapitalLetter       CharLoc2;
  329.  
  330.         CharLoc1 = CharPar1;
  331.         CharLoc2 = CharLoc1;
  332.         if (CharLoc2 != CharPar2)
  333.                 return (Ident1);
  334.         else
  335.                 return (Ident2);
  336. }
  337.  
  338. boolean Func2(StrParI1, StrParI2)
  339. String30        StrParI1;
  340. String30        StrParI2;
  341. {
  342.         REG OneToThirty         IntLoc;
  343.         REG CapitalLetter       CharLoc;
  344.  
  345.         IntLoc = 1;
  346.         while (IntLoc <= 1)
  347.                 if (Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
  348.                 {
  349.                         CharLoc = 'A';
  350.                         ++IntLoc;
  351.                 }
  352.         if (CharLoc >= 'W' && CharLoc <= 'Z')
  353.                 IntLoc = 7;
  354.         if (CharLoc == 'X')
  355.                 return(TRUE);
  356.         else
  357.         {
  358.                 if (strcmp(StrParI1, StrParI2) > 0)
  359.                 {
  360.                         IntLoc += 7;
  361.                         return (TRUE);
  362.                 }
  363.                 else
  364.                         return (FALSE);
  365.         }
  366. }
  367.  
  368. boolean Func3(EnumParIn)
  369. REG Enumeration EnumParIn;
  370. {
  371.         REG Enumeration EnumLoc;
  372.  
  373.         EnumLoc = EnumParIn;
  374.         if (EnumLoc == Ident3) return (TRUE);
  375.         return (FALSE);
  376. }
  377.  
  378. #ifdef  NOSTRUCTASSIGN
  379. memcpy(d, s, l)
  380. register char   *d;
  381. register char   *s;
  382. int     l;
  383. {
  384.         while (l--) *d++ = *s++;
  385. }
  386. #endif
  387.  
  388. /*
  389.  *      Library function for compilers with no time(2) function in the
  390.  *      library.
  391.  */
  392. #ifdef  NOTIME
  393. long    time(p)
  394. long    *p;
  395. {               /* CI-C86 time function - don't use around midnight */
  396.         long    t;
  397.         struct regval {unsigned int ax,bx,cx,dx,si,di,ds,es; } regs;
  398.  
  399.         regs.ax = 0x2c00;
  400.         sysint21(®s, ®s);
  401.         t = ((regs.cx>>8)*60L + (regs.cx & 0xff))*60L + (regs.dx>>8);
  402.         if (p) *p = t;
  403.         return t;
  404. }
  405. #endif
  406.